{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_ackley:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ackley\n",
    "\n",
    "The Ackley function is widely used for testing optimization algorithms. In its two-dimensional form, as shown in the plot above, it is characterized by a nearly flat outer region, and a large hole at the centre. The function poses a risk for optimization algorithms, particularly hillclimbing algorithms, to be trapped in one of its many local minima. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Definition**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "\\begin{split}\n",
    "f(x) &=& \\,-a \\exp{ \\Bigg[ -b \\, \\sqrt{ \\frac{1}{n} \\sum_{i=1}^{n}{x_i}^2 } \\Bigg]} - \\exp{ \\Bigg[ \\frac{1}{n}\\sum_{i=1}^{n}{cos(c x_i)} \\Bigg] } + a + e, \\\\[2mm]\n",
    "&& a = \\;20, \\quad b = \\; \\frac{1}{5}, \\quad c = \\;2 \\pi \\\\[2mm]\n",
    "&&-32.768 \\leq x_i \\leq 32.768, \\quad i=1 \\ldots,n \\\\[4mm]\n",
    "\\end{split}\n",
    "\\end{align}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Optimum**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$f(x^*) = 0 \\; \\text{at} \\; x^* = (0,\\ldots,0) $$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Fitness Landscape**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "from pymoo.problems import get_problem\n",
    "from pymoo.visualization.fitness_landscape import FitnessLandscape\n",
    "\n",
    "problem = get_problem(\"ackley\", n_var=2, a=20, b=1/5, c=2 * np.pi)\n",
    "\n",
    "FitnessLandscape(problem, angle=(45, 45), _type=\"surface\").show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "FitnessLandscape(problem, _type=\"contour\", colorbar=True).show()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
